class ApiSource(BaseModel):
householder:str
Amount:int #配合規格,自動補上小數點後兩位00
OrderNo:str
PayType:str
訂單建置API
@app.post("/sinopacApi_Order", summary="永豐建置訂單API" )# , response_model=ApiResultGet
async def sinopacApi_Order(apiparams: ApiSource):
start = time.time()
# ShopNo 由主辦單位提供,此處示例以 xxx 取代
Shop_No = {'ShopNo':"NAxxx_001"}
NonceValue=getNonce(Shop_No)
SHAValue ,IVValue= getSHAValue(NonceValue)
hashID = getAESKey()
lastDate= datetime.date.today() + datetime.timedelta(days=1)
print("lastDate",str(lastDate).replace("-",""))
print("apiparams.PayType => ",apiparams.PayType)
OrderNo_total=apiparams.PayType+"_"+apiparams.OrderNo+"_"+str(datetime.datetime.now().timestamp())
if apiparams.PayType=="A":
send_message_ori = {
"ShopNo": Shop_No["ShopNo"],
"OrderNo": OrderNo_total,
"Amount": apiparams.Amount*100,
"CurrencyID": "TWD",
"PayType": apiparams.PayType, #管理費僅用匯款,無信用卡繳費模式
"ATMParam": {"ExpireDate":str(lastDate).replace("-","")},
"CardParam": {},
"ConvStoreParam": {},
"PrdtName": "order",
"Param1": apiparams.householder,
"Param2": apiparams.OrderNo,
"ReturnURL": "http://10.11.22.113:8803/QPay.ApiClient/Store/Return",
"BackendURL": "http://10.11.22.113:8803/QPay.ApiClient/AutoPush/PushSuccess",
}
elif apiparams.PayType=="C":
send_message_ori = {
"ShopNo": Shop_No["ShopNo"],
"OrderNo": OrderNo_total,
"Amount": apiparams.Amount*100,
"CurrencyID": "TWD",
"PayType": apiparams.PayType, #管理費僅用匯款,無信用卡繳費模式
"ATMParam": {},
"CardParam": {"AutoBilling":"Y"},
"ConvStoreParam": {},
"PrdtName": "order",
"Param1": apiparams.householder,
"Param2": apiparams.OrderNo,
"ReturnURL": "http://10.11.22.113:8803/QPay.ApiClient/Store/Return",
"BackendURL": "http://10.11.22.113:8803/QPay.ApiClient/AutoPush/PushSuccess",
}
print('send_message_ori => ',send_message_ori)
send_message_TextHash=getMessageTextHash(send_message_ori,NonceValue,hashID)
SignValue = getSignValue(send_message_TextHash)
jsonText=json.dumps(send_message_ori, ensure_ascii=False).replace(' ', "")
print(jsonText)
aes_encrypt_str = AES_CBC_Encrpt(hashID, IVValue, jsonText)
send_POST_message={
"Version": "1.0.0",
"ShopNo": Shop_No["ShopNo"],
"APIService": "OrderCreate",
"Sign": SignValue,
"Nonce": NonceValue,
"Message": aes_encrypt_str
}
print('send_POST_message => ',send_POST_message)
requests_link = 'https://apisbx.sinopac.com/funBIZ/QPay.WebAPI/api/Order'
r = requests.post(url = requests_link, json = send_POST_message )
print('status_code => ',r.status_code)
# print('status_json => ',r.json())
print('status_Nonce => ',r.json()["Nonce"])
NonceValue=r.json()["Nonce"]
SHAValue ,IVValue= getSHAValue(NonceValue)
hashID = getAESKey()
aes_decrypt_str = AES_CBC_Decrypt(hashID, iv=IVValue, data=r.json()["Message"])
print(f'解密結果為: {aes_decrypt_str}')
decrypt_dist=json.loads(aes_decrypt_str)
r.close()
return {"message": "success", 'time': time.time() - start ,"decrypt_dist" : decrypt_dist}
uvicorn app.main:app --host 0.0.0.0 --port 80
設定
執行結果
以下為執行結果,主要得到的資訊為查詢完成("Description": "S0000 – 處理成功"),同時也可以得到匯款帳,提供客戶直接使用ATM匯入費用。
訂單建立之後,就是要來查看繳費紀錄囉~明天見